Release 10.1A: OpenEdge Development:
Web Services
Using a client-created SOAP request header
This example shows how you might create a SOAP header internally to use as an initial SOAP request header, as opposed to recycling a header previously received in a SOAP response message (described in previous examples). This is an example of the header created by the client for the Web service:
The client creates a header very similar to the headers described in the previous examples. The
<UserName>and<Password>elements, in this case, provide user authentication for each Web service request. The Web service requires this authentication for every Web service request.The following is the mainline of a procedure that invokes the Web service to create the initial SOAP request header containing a username and password node. This code:
- Defines several mainline variables, including handles to access the global SOAP header (
g_header) created for requests and its XML, and variables to hold the username (cUsername) and password (cPassword) values.- Builds the global request header used for all requests (see the "Procedure to create a SOAP request header" section).
- Registers the request header (
ReqHandler) handler after connecting to the Web service and instantiating theHeaderSoapport type procedure object.- Runs the
HelloMyWorldprocedure to invoke a Web service operation, passing back the global SOAP request header created by the client (see the "Request header handler for passing a globally-created header object" section).- Cleans up the global objects maintained in its context and disconnects from the Web service. Note that one of the objects it deletes is the global SOAP request header create by the client.
Procedure to create a SOAP request header
This is the procedure (
BuildRequestHeader) that creates the global SOAP request header that the client sends in all requests to the Web service:
This code:
- Defines a single output parameter to return the global SOAP header object that it creates to the client mainline context.
- Defines a handle variable (
hHeaderEntryref) to reference the SOAP header entryref object, and a variable (ClientNS) that specifies the namespace for the SOAP header entry that it creates.- Creates the global SOAP header object that references the XML for the header using the
CREATESOAP-HEADERstatement, and creates the SOAP header entryref object that references the XML for the header entry using theCREATESOAP-HEADER-ENTRYREFstatement.- Creates the x-document and x-noderef objects required to build the XML to be added as the header entry for the global SOAP header.
- Adds a header entry to the newly-created SOAP header object, referenced by the
hHeaderEntryrefobject, using theADD-HEADER-ENTRY( )method.Note: The namespace attribute specifying- Creates the root node (
<AuthHeader>element) for the header entry in the working x-document object.http://www.w3.org/2000/xmlns/is a requirement of the DOM. For more information, see the information on XML support in OpenEdge Development: Programming Interfaces .- Creates the
<UserName>element as a child node of the header entry.- Creates the
<Password>element as a second child node of the header entry.- Assigns the header entry in the global SOAP header object to the XML for the
<AuthHeader>element of the x-document object using theSET-NODE( )method.
- Cleans up by deleting all the helper objects created in the procedure before returning to the client mainline.
Request header handler for passing a globally-created header object
This is the SOAP request header handler (
ReqHandler) that passes the global SOAP request header created by the client and the Web service for each request:
This code:
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |